import json
import time

import requests
import subprocess
from functools import partial

subprocess.Popen = partial(subprocess.Popen, encoding='utf-8')
# import execjs
# import hashlib

# with open('h5st516.js', 'r', encoding='utf-8') as f:
#     js = f.read()

# js_com = execjs.compile(js)


# def sha_256(message):
#     return hashlib.sha256(message.encode('utf-8')).hexdigest()


# def convert_cookie_dict_to_string(cookie_dict):
#     # Join each key-value pair with '=' and then join all pairs with '; '
#     cookie_string = '; '.join([f"{key}={value}" for key, value in cookie_dict.items()])
#     return cookie_string


# url = "https://api.m.jd.com/"


# def generate_h5st(params):
#     # 解析原始 body
#     body_str = params['body']
#     body = json.loads(body_str) if isinstance(body_str, str) else body_str

#     # 创建用于 SHA256 加密的 boddy
#     boddy = {
#         "skuId": body['skuId'],
#         "cat": body['cat'],
#         "area": body['area'],
#         "shopId": body['shopId'],
#         "venderId": body['venderId'],
#         "paramJson": body['paramJson'],
#         "num": body['num'],
#         "bbTraffic": body['bbTraffic'],
#         "canvasType": body['canvasType'],
#         "giftServiceIsSelected": body['giftServiceIsSelected'],
#         "customInfoId": body['customInfoId']
#     }

#     # 创建用于生成 h5st 的 a 对象
#     a = {
#         "appid": params.get('appid', 'pc-item-soa'),
#         "body": sha_256(json.dumps(boddy, separators=(',', ':'))),
#         "clientVersion": params.get('clientVersion', '1.0.0'),
#         "client": params.get('client', 'pc'),
#         "functionId": params.get('functionId', 'pc_detailpage_wareBusiness'),
#         "t": int(time.time() * 1000),  # 使用当前时间戳
#     }

#     # 调用 JS 的 PSign.sign 方法生成 h5st
#     h5st = js_com.call('getH5st', a)

#     return h5st


# params = {
#     "appid": "pc-item-soa",
#     "functionId": "pc_detailpage_wareBusiness",
#     "client": "pc",
#     "clientVersion": "1.0.0",
#     "t": "1755837555696",
#     "body": '{"skuId":10155078248717,"cat":"670,671,672","area":"19_1607_4773_62123","shopId":"12211345","venderId":12522313,"paramJson":"{\\"platform2\\":\\"1\\",\\"colType\\":0,\\"specialAttrStr\\":\\"p0ppppppppp3p1ppppppppppppppp\\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hfMTgvFqkbIz8rM-h-T-dLEuYfZB5xD;cc400660f22efc7873e6afd8153f5d58;gRaW989Gy8bE_oLE7w-Gy8rFvM7MtoLI4wrJ1R6G88bG_wPD9k7J1RLHxgKJ",
#     "x-api-eid-token": "jdd03GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBEAAAAMY2AJLHMQAAAAACQWYYDGYECJI4MX",
#     "loginType": "3",
#     "scval": "10155078248717",
#     "uuid": "181111935.1751545604909534518369.1751545604.1755078672.1755835933.17",
# }

# h5st = generate_h5st(params)
# print(h5st)
# print(len(h5st))
# params['h5st'] = h5st
# headers = {
#     "accept": "application/json, text/javascript, */*; q=0.01",
#     "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,ar;q=0.7",
#     "cache-control": "no-cache",
#     "origin": "https://item.jd.com",
#     "pragma": "no-cache",
#     "priority": "u=1, i",
#     "referer": "https://item.jd.com/",
#     "sec-ch-ua": '"Not;A=Brand";v="99", "Microsoft Edge";v="139", "Chromium";v="139"',
#     "sec-ch-ua-mobile": "?0",
#     "sec-ch-ua-platform": '"Windows"',
#     "sec-fetch-dest": "empty",
#     "sec-fetch-mode": "cors",
#     "sec-fetch-site": "same-site",
#     "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0",
#     "x-referer-page": "https://item.jd.com/10155078248717.html",
#     "x-rp-client": "h5_1.0.0",
# }
# cookies = {
#     "b_webp": "1",
#     "b_avif": "1",
#     "jcap_dvzw_fp": "_HIVLiZCIEZDIcHwXjPU43al5uvsYIwPfs4O6VE9nqABptbi3ASG0seWjzU_o2F4bpTtKrH1VphdN9RwziykSA==",
#     "whwswswws": "",
#     "__jdu": "1751545604909534518369",
#     "pinId": "briEibRb-h1YgxkG81uaz7V9-x-f3wj7",
#     "pin": "jd_7eac037a858fc",
#     "unick": "jd_8js7q5tn2s7n2h",
#     "_tp": "aO5XtogPiplRTZPyN6P5Vkd5JC%2FQJe7kEmh0g0oTaNI%3D",
#     "_pst": "jd_7eac037a858fc",
#     "shshshfpa": "ab96e4b0-82d6-a907-9206-6c096fe807bb-1751545628",
#     "shshshfpx": "ab96e4b0-82d6-a907-9206-6c096fe807bb-1751545628",
#     "autoOpenApp_downCloseDate__jd_czlogin_openapp_": "1752224419174_1",
#     "b_dw": "1912",
#     "b_dh": "954",
#     "b_dpr": "1",
#     "commonAddress": "0",
#     "regionAddress": "1%2C72%2C55674%2C0",
#     "autoOpenApp_downCloseDate_autoOpenApp_autoPromptly": "1752227819923_1",
#     "autoOpenApp_downCloseDate_jd_homePage": "1752462226750_1",
#     "autoOpenApp_downCloseDate_auto": "1752462295553_1800000",
#     "pt_st": "1_QNKa_p1pyRBuRGl7XqjS4ZLHq52uvHozXQu0yZZJaZBykE4huAxadU8rhTxkOed5v-IuGcuXOYsk2aIeXaDCbyBsLjrt7MdvOSvBodXxczB1FkZgSNPx2J-jeoajHnfW39S6QiYrPFEIK1rDtYq4I4SRP4BxLa81ywRy9N0XGlJp_KtCaUMwl_dWLrRUp5syXYAGm0trSW0tTUQiv77qSqdfTbhMefstFJyB3qwZ",
#     "mba_muid": "1751545604909534518369",
#     "__jdv": "181111935%7Cdirect%7C-%7Cnone%7C-%7C1755078672567",
#     "areaId": "19",
#     "ipLoc-djd": "19-1607-4773-62123",
#     "mba_sid": "17558359337691957015350.1",
#     "wlfstk_smdl": "elg8xch7x22hv40dy2sj1s56ixomgd4v",
#     "TrackID": "1D57218kMnWjkpnJQLsHivNypNAxTRAsH6sw2BN-9lSsXwI3vFWFvH2UIb175GG4Bzl3QwpzBntd73Lt37-eZoqqd0mkQML4FVCMvYY32zFn2HTzoNS9VaFX0JBOmMv8v",
#     "thor": "2B3FAB022DDA7FFF772855629D82E8BA86B6B654FC776E1930AA7FEB1EB3100E0EFF60D94A82F4A76FF44BB8A2F0380724033DC14E0D5D2081A0FC6D88DC7E0B0DEF0E1C2ADDC814192BF7072EEE64A74C780247D2D0E051B55ECA1FE65331C43C6FF19DA524CAADE28EBBFF5A737F1C2C0E87642DC019942EAB6F2F3F7490C9A4A015D11BEABC94DF50F902872FFCFEFA5193B4F2D115B9F70919BE14A4EC97",
#     "light_key": "AASBKE7rOxgWQziEhC_QY6yaI60husQyf2CtGBxun8l2DhUKCpGjBi33ERp1eXCQfzDa618T",
#     "ceshi3.com": "000",
#     "cn": "12",
#     "3AB9D23F7A4B3C9B": "GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBE",
#     "token": "533ccb32a6bb91b752a10225248dd4ad,3,975465",
#     "__jda": "181111935.1751545604909534518369.1751545604.1755078672.1755835933.17",
#     "__jdc": "181111935",
#     "__jdb": "181111935.6.1751545604909534518369|17.1755835933",
#     "3AB9D23F7A4B3CSS": "jdd03GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBEAAAAMY2AJLHMQAAAAACQWYYDGYECJI4MX",
#     "_gia_d": "1",
#     "flash": "3_NkbgiVYYqFHvTVIKPtAzvQxRpwP17ROKpc0zKHn1yhG_30aBwRVjk4br_52fmR1rYe54iZZc3eUqN_ajwDDAjuScyJalyHtUNHuDLg7d2uvaL2NnQY--HMHLQqtg4adLo7Xn2mBbFHO3ejNSjHDvWz4qYe4LJCstiyodE15r_oZf3JqhVLzDPq**",
#     "jsavif": "1",
#     "shshshfpb": "BApXShXAa0_1AYEqgcJFHsyDPBX7ULrZhBhMVUQdh9xJ1MppMe462",
#     "sdtoken": "AAbEsBpEIOVjqTAKCQtvQu171V_UpA-KuVfQ8ccRBzVb-BwJ2qDMzq23KfIRD775dqtjFUxVZg6QzJMK_cO7a4MwgilnOSePHoOZ7amnqp1nMoTVv5oDsM108R5xQHGKE9YHIity2qN5",
# }
# response = requests.get(url, headers=headers, cookies=cookies, params=params)
# with open("100114711942.json", "w", encoding="utf-8") as f:
#     f.write(response.text)
# print(response.text)
# print(response)


headers = {
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,ar;q=0.7",
    "cache-control": "no-cache",
    "origin": "https://item.jd.com",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://item.jd.com/",
    "sec-ch-ua": '"Not;A=Brand";v="99", "Microsoft Edge";v="139", "Chromium";v="139"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"Windows"',
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0",
    "x-referer-page": "https://item.jd.com/10155078248717.html",
    "x-rp-client": "h5_1.0.0",
}
cookies = {
    "b_webp": "1",
    "b_avif": "1",
    "jcap_dvzw_fp": "_HIVLiZCIEZDIcHwXjPU43al5uvsYIwPfs4O6VE9nqABptbi3ASG0seWjzU_o2F4bpTtKrH1VphdN9RwziykSA==",
    "whwswswws": "",
    "__jdu": "1751545604909534518369",
    "pinId": "briEibRb-h1YgxkG81uaz7V9-x-f3wj7",
    "pin": "jd_7eac037a858fc",
    "unick": "jd_8js7q5tn2s7n2h",
    "_tp": "aO5XtogPiplRTZPyN6P5Vkd5JC%2FQJe7kEmh0g0oTaNI%3D",
    "_pst": "jd_7eac037a858fc",
    "shshshfpa": "ab96e4b0-82d6-a907-9206-6c096fe807bb-1751545628",
    "shshshfpx": "ab96e4b0-82d6-a907-9206-6c096fe807bb-1751545628",
    "autoOpenApp_downCloseDate__jd_czlogin_openapp_": "1752224419174_1",
    "b_dw": "1912",
    "b_dh": "954",
    "b_dpr": "1",
    "commonAddress": "0",
    "regionAddress": "1%2C72%2C55674%2C0",
    "autoOpenApp_downCloseDate_autoOpenApp_autoPromptly": "1752227819923_1",
    "autoOpenApp_downCloseDate_jd_homePage": "1752462226750_1",
    "autoOpenApp_downCloseDate_auto": "1752462295553_1800000",
    "pt_st": "1_QNKa_p1pyRBuRGl7XqjS4ZLHq52uvHozXQu0yZZJaZBykE4huAxadU8rhTxkOed5v-IuGcuXOYsk2aIeXaDCbyBsLjrt7MdvOSvBodXxczB1FkZgSNPx2J-jeoajHnfW39S6QiYrPFEIK1rDtYq4I4SRP4BxLa81ywRy9N0XGlJp_KtCaUMwl_dWLrRUp5syXYAGm0trSW0tTUQiv77qSqdfTbhMefstFJyB3qwZ",
    "mba_muid": "1751545604909534518369",
    "__jdv": "181111935%7Cdirect%7C-%7Cnone%7C-%7C1755078672567",
    "areaId": "19",
    "ipLoc-djd": "19-1607-4773-62123",
    "mba_sid": "17558359337691957015350.1",
    "wlfstk_smdl": "elg8xch7x22hv40dy2sj1s56ixomgd4v",
    "TrackID": "1D57218kMnWjkpnJQLsHivNypNAxTRAsH6sw2BN-9lSsXwI3vFWFvH2UIb175GG4Bzl3QwpzBntd73Lt37-eZoqqd0mkQML4FVCMvYY32zFn2HTzoNS9VaFX0JBOmMv8v",
    "thor": "2B3FAB022DDA7FFF772855629D82E8BA86B6B654FC776E1930AA7FEB1EB3100E0EFF60D94A82F4A76FF44BB8A2F0380724033DC14E0D5D2081A0FC6D88DC7E0B0DEF0E1C2ADDC814192BF7072EEE64A74C780247D2D0E051B55ECA1FE65331C43C6FF19DA524CAADE28EBBFF5A737F1C2C0E87642DC019942EAB6F2F3F7490C9A4A015D11BEABC94DF50F902872FFCFEFA5193B4F2D115B9F70919BE14A4EC97",
    "light_key": "AASBKE7rOxgWQziEhC_QY6yaI60husQyf2CtGBxun8l2DhUKCpGjBi33ERp1eXCQfzDa618T",
    "ceshi3.com": "000",
    "cn": "12",
    "3AB9D23F7A4B3C9B": "GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBE",
    "token": "533ccb32a6bb91b752a10225248dd4ad,3,975465",
    "__jda": "181111935.1751545604909534518369.1751545604.1755078672.1755835933.17",
    "__jdc": "181111935",
    "__jdb": "181111935.6.1751545604909534518369|17.1755835933",
    "3AB9D23F7A4B3CSS": "jdd03GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBEAAAAMY2AJLHMQAAAAACQWYYDGYECJI4MX",
    "_gia_d": "1",
    "flash": "3_NkbgiVYYqFHvTVIKPtAzvQxRpwP17ROKpc0zKHn1yhG_30aBwRVjk4br_52fmR1rYe54iZZc3eUqN_ajwDDAjuScyJalyHtUNHuDLg7d2uvaL2NnQY--HMHLQqtg4adLo7Xn2mBbFHO3ejNSjHDvWz4qYe4LJCstiyodE15r_oZf3JqhVLzDPq**",
    "jsavif": "1",
    "shshshfpb": "BApXShXAa0_1AYEqgcJFHsyDPBX7ULrZhBhMVUQdh9xJ1MppMe462",
    "sdtoken": "AAbEsBpEIOVjqTAKCQtvQu171V_UpA-KuVfQ8ccRBzVb-BwJ2qDMzq23KfIRD775dqtjFUxVZg6QzJMK_cO7a4MwgilnOSePHoOZ7amnqp1nMoTVv5oDsM108R5xQHGKE9YHIity2qN5",
}
url = "https://api.m.jd.com/"
params = {
    "appid": "pc-item-soa",
    "functionId": "pc_detailpage_wareBusiness",
    "client": "pc",
    "clientVersion": "1.0.0",
    "t": "1755837555696",
    "body": '{"skuId":10155078248717,"cat":"670,671,672","area":"19_1607_4773_62123","shopId":"12211345","venderId":12522313,"paramJson":"{\\"platform2\\":\\"1\\",\\"colType\\":0,\\"specialAttrStr\\":\\"p0ppppppppp3p1ppppppppppppppp\\",\\"skuMarkStr\\":\\"10\\"}","num":1,"bbTraffic":"","canvasType":1,"giftServiceIsSelected":"","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gy8bE_oLE7w-Gy8rFvM7MtoLI4wrJ1R6G88bG_wPD9k7J1RLHxgKJ",
    "x-api-eid-token": "jdd03GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBEAAAAMY2AJLHMQAAAAACQWYYDGYECJI4MX",
    "loginType": "3",
    "scval": "10155078248717",
    "uuid": "181111935.1751545604909534518369.1751545604.1755078672.1755835933.17",
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)

print(response.text)
print(response)
